package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.IView.IEngineeringInstallCompleteForManagerView;
import com.cloudsigns.factorymanager2.engineering.IView.IEngineeringInstallOrderDetailView;
import com.cloudsigns.factorymanager2.engineering.adapter.GridAdapter;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.engineering.presenter.EngineeringInstallCompleteForManagerPresenter;
import com.cloudsigns.factorymanager2.engineering.presenter.EngineeringInstallOrderDetailPresenter;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;

import java.util.ArrayList;
import java.util.List;

public class EngineeringInstallCompletionOrderForManagerActivity1 extends Activity implements IEngineeringInstallOrderDetailView, View.OnClickListener {
    private final String TAG = EngineeringInstallCompletionOrderForManagerActivity1.class.getSimpleName();
    private TextView tv_title;
    private ViewGroup rl_back;
    private View rl_project;
    private TextView tv_project_name, tv_engineering_name;
    private ImageView img_project_select;
    private LinearLayout ll_engineering_info_content;
    private TextView edt_project_manager, edt_engineering_manager, edt_engineering_team, edt_finish_date, edt_completionorder_date;
    private GridView gridview_completion, gridview_texie_photo, gridview_other_photo;
    private View rl_evalutaion;
    private TextView tv_construction_quality, tv_onstruction_schedule, tv_construction_environment, tv_construction_safe, tv_final_evaluation, tv_completion_people, tv_completion_time;

    private String quality, schedule, environment, safe, final_evaluation;
    private OrderParentBean orderParentBean;
    private EngineeringInstallationOrderBean engineeringInstallationOrderBean;
    private EngineeringInstallOrderDetailPresenter engineeringInstallOrderDetailPresenter;
    private EngineeringInstallCompleteForManagerPresenter engineeringInstallCompleteForManagerPresenter;

    private GridAdapter gridview_completiondapter, gridview_texie_photoadapter, gridview__other_photoadapter;

    private List<String> serverimgUrlListList = new ArrayList<>();
    private List<String> serverortherimgUrlListList = new ArrayList<>();
    private List<String> servertexieimgUrlListList = new ArrayList<>();


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }


        setContentView(R.layout.layout_engineeringinstall_completionorder_for_manager1);

        initView();
    }


    private void initView() {
        tv_title = findViewById(R.id.tv_title);
        rl_back = findViewById(R.id.rl_back);
        rl_project = findViewById(R.id.rl_project);
        tv_project_name = findViewById(R.id.tv_project_name);
        tv_engineering_name = findViewById(R.id.tv_engineering_name);
        img_project_select = findViewById(R.id.img_project_select);
        ll_engineering_info_content = findViewById(R.id.ll_engineering_info_content);
        edt_project_manager = findViewById(R.id.edt_project_manager);
        edt_engineering_manager = findViewById(R.id.edt_engineering_manager);
        edt_engineering_team = findViewById(R.id.edt_engineering_team);
        edt_finish_date = findViewById(R.id.edt_finish_date);
        edt_completionorder_date = findViewById(R.id.edt_completionorder_date);
        gridview_completion = findViewById(R.id.gridview_completion);
        gridview_texie_photo = findViewById(R.id.gridview_texie_photo);
        gridview_other_photo = findViewById(R.id.gridview__other_photo);
        rl_evalutaion = findViewById(R.id.rl_evalutaion);
        tv_construction_quality = findViewById(R.id.tv_construction_quality);
        tv_onstruction_schedule = findViewById(R.id.tv_onstruction_schedule);
        tv_construction_environment = findViewById(R.id.tv_construction_environment);
        tv_construction_safe = findViewById(R.id.tv_construction_safe);
        tv_final_evaluation = findViewById(R.id.tv_final_evaluation);
        tv_completion_people = findViewById(R.id.tv_completion_people);
        tv_completion_time = findViewById(R.id.tv_completion_time);


        gridview_completion.setNumColumns(3);
        gridview_texie_photo.setNumColumns(3);
        gridview_other_photo.setNumColumns(3);

        gridview_completiondapter = new GridAdapter(this);
        gridview_texie_photoadapter = new GridAdapter(this);
        gridview__other_photoadapter = new GridAdapter(this);

        gridview_completiondapter.setData(serverimgUrlListList);
        gridview_texie_photoadapter.setData(servertexieimgUrlListList);
        gridview__other_photoadapter.setData(serverortherimgUrlListList);

        gridview_completion.setAdapter(gridview_completiondapter);
        gridview_texie_photo.setAdapter(gridview_texie_photoadapter);
        gridview_other_photo.setAdapter(gridview__other_photoadapter);


        rl_back.setOnClickListener(this);
        img_project_select.setOnClickListener(this);


        tv_title.setText("工程安装");
        img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);
        Intent mIntent = getIntent();
        if (null != mIntent) {
            orderParentBean = (OrderParentBean) mIntent.getSerializableExtra(ConstantUtil.KEY_1);
        }

        engineeringInstallOrderDetailPresenter = new EngineeringInstallOrderDetailPresenter(this);
        engineeringInstallOrderDetailPresenter.getEngineeringInstallOrderDetail();
    }


    private void initData() {

        if (null != engineeringInstallationOrderBean) {
            edt_project_manager.setText(engineeringInstallationOrderBean.getCreateOrderAccountName());
            edt_engineering_manager.setText(engineeringInstallationOrderBean.getReceiveAccountName());
            edt_engineering_team.setText(engineeringInstallationOrderBean.getAssignReceiveAccountName());
            edt_finish_date.setText(DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getFinishDate()));
            edt_completionorder_date.setText(DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getCompleteDate()));
            tv_completion_people.setText(engineeringInstallationOrderBean.getCreateOrderAccountName());


            tv_project_name.setText(engineeringInstallationOrderBean.getProjectName());
            tv_engineering_name.setText(" / " + engineeringInstallationOrderBean.getEngineeringName());
//            edt_completionorder_date.setText(DateUtil.getYyyy_Mm_Dd(engineeringInstallationOrderBean.getFinishDate()));

            CommonEnum.CompleteStatus completeStatus = engineeringInstallationOrderBean.getCompleteStatus();

            List<String> completeImageList = engineeringInstallationOrderBean.getCompleteImageList();
            if (null != completeImageList) {
                gridview_completiondapter.setData(completeImageList);
                gridview_completiondapter.notifyDataSetChanged();
            }
            List<String> completeCloseUpImageList = engineeringInstallationOrderBean.getCompleteCloseUpImageList();
            if (null != completeCloseUpImageList) {
                gridview_texie_photoadapter.setData(completeCloseUpImageList);
                gridview_texie_photoadapter.notifyDataSetChanged();
            }

            List<String> completeOtherImageList = engineeringInstallationOrderBean.getCompleteOtherImageList();
            if (null != completeOtherImageList) {
                gridview__other_photoadapter.setData(completeOtherImageList);
                gridview__other_photoadapter.notifyDataSetChanged();
            }
        }
    }


    private void showEngineeringInfoDialog() {
        if (ll_engineering_info_content.getVisibility() == View.VISIBLE) {
            ll_engineering_info_content.setVisibility(View.GONE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_down_icon);
        } else {
            ll_engineering_info_content.setVisibility(View.VISIBLE);
            img_project_select.setBackgroundResource(R.mipmap.arrow_top);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
            case R.id.img_project_select:
                showEngineeringInfoDialog();
                break;
        }
    }


    @Override
    public String getItemId() {
        return null;
    }

    @Override
    public long getFeedbackDate() {
        return 0;
    }

    @Override
    public String getOrderId() {
        if (null != orderParentBean)
            return orderParentBean.getId();
        return "";
    }

    @Override
    public void getEngineeringInstallOrderDetailSuccessed(EngineeringInstallationOrderBean orderBean) {
        engineeringInstallationOrderBean = orderBean;
        initData();
    }

    @Override
    public void getEngineeringInstallOrderDetailFailed(String desc) {
        Toast.makeText(this, desc, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
